import {
  Mesh,
  PlaneBufferGeometry,
  MeshStandardMaterial,
  Group,
  Sprite,
  SpriteMaterial,
} from 'three'
import { pikachiuPromise } from './TLoadModle'
import { pictureTexture, tipsTexture } from './Ttextures'

export const groupPromise = new Promise((resolve, reject) => {
  const group = new Group()

  //标签(平面几何体)
  // const tip = new Mesh(
  //   new PlaneBufferGeometry(60, 30),
  //   new MeshStandardMaterial({
  //     map: tipsTexture, //纹理贴图
  //   })
  // )
  // 精灵是一个总是面朝着摄像机的平面，通常含有使用一个半透明的纹理
  const tip = new Sprite(
    new SpriteMaterial({
      map: tipsTexture,
      sizeAttenuation: true, //是否随着摄像机透视
    })
  )
  tip.position.y = 15
  tip.scale.set(16, 9, 1)
  // tip.scale.set(0.5, 0.5, 0.5)

  group.add(tip)
  // 图片(平面几何体)
  const plane = new Mesh(
    new PlaneBufferGeometry(100, 100),
    new MeshStandardMaterial({
      map: pictureTexture, //纹理贴图
    })
  )
  plane.position.y = 50
  // plane.position.z = 50
  plane.scale.set(0.5, 0.5, 0.5)

  // plane.onBeforeRender = (renderer, scene, camera) => {
  //   plane.lookAt(camera.position) //朝向摄像机方向
  // }

  // plane.onAfterRender

  group.add(plane)

  pikachiuPromise
    .then((frame) => {
      group.add(frame)
      group.position.z = 50
      // group.updateMatrix()
      // group.updateMatrixWorld()
      resolve(group)
    })
    .catch((err) => {
      reject(err)
    })
})
